/* symboltable class */
#pragma once

#include <vector>
#include <string>
#include <map>

class Label;
class Node;

class SymbolTable
{
private:
	SymbolTable* parent;		// chaining scopes
	std::map<std::string, Node*> table;
	std::map<std::string, Label*> jumps;

public:
	SymbolTable(SymbolTable* parent = NULL) {
		this->parent = parent;
	}
	~SymbolTable();

	void SetParent(SymbolTable* parent);

	// Adds a base address to all registered label targets
	// TODO: labels really should be factored out of this class and into Module
	void AddBaseAddress(unsigned int base);

	bool Define(const std::string& name, Node* node);

	bool DefineLabel(Label* label);

	bool DefineLabel(const std::string& name, Label* label);

	Node* Lookup(const std::string& name) const;

	Label* LookupLabel(const std::string& name) const;

	std::string ToString() const;

	std::string JumpsTable() const;

	const std::map<std::string, Label*>& GetJumpTable() const;
};

